package com.aistar.util;

import java.util.Random;

public class SmsUtil {

    public static String getSms(String telNo) {
        String accessKey = "5ec3ce37efb9a35396d4cc2f";
        String secretKey = "7e6bc536eb654740bb5e81180a1b66e8";
        String code  = getRandomNum();
        try {
            SmsSingleSender smsSingleSender = new SmsSingleSender(accessKey, secretKey);
            SmsSingleSenderResult singleSenderResult;

            //普通单发,注意前面必须为【】符号包含，置于头或者尾部。
            singleSenderResult = smsSingleSender.send(0, "86", telNo, "【Kewail科技】尊敬的用户：您的验证码："+code+"，工作人员不会索取，请勿泄漏。", "", "");
            System.out.println(singleSenderResult);


        } catch (Exception e) {
            e.printStackTrace();
        }

        return code;
    }

    public static String getRandomNum() {

        Random random = new Random();
        String result = "";
        for (int i = 0; i < 6; i++) {
            result += random.nextInt(10);
        }

        return result;
    }

}
